<?php
namespace app\admin\controller;
use \think\Controller;
use \think\Session;
use \think\Db;
class Formshowpiccomment extends Common
{
	public function add($id){
    
    $this->assign("showpicid",$id);
		return $this->fetch();
	}

	public function edit($id){
		$result = Db::name("comments")->where('s_id',$id)->find();
    $this->assign("showpiccomment",$result);
    return $this->fetch();
	}
  public function addshowpiccomment($id){
      if (request()->isPost()) {
        $data=[
                  'u_id'=>9,
                  's_intro'=>input('param.commentcontent'),
                  's_date'=>date('Y-m-d H:i:s'),
                  'pi_id'=>$id,
            ];
        $res=Db::name('comments')->insert($data);
        
        //处理结果
        if ($res) {
          $this->success("添加晒图评论成功",url('showpiccomment/index',['id'=>$id]));
        }
        else {
          $this->error("添加晒图评论失败",url('showpiccomment/index',['id'=>$id]));
        }
      }
  }
	
  public function updateshowpiccomment($id){
    if (request()->isPost()) {
        $data = array();
        $data=[
                  'commentcontent'=>input('param.commentcontent'),
            ];
        $res=Db::name('showpiccomment')->where('showpiccommentid',$id)->update($data);
        
        //处理结果
        if ($res!==false) {
          $this->success("修改晒图评论成功",url('showpiccomment/index',['id'=>input('showpicid')]));
        }
        else {
          $this->error("修改晒图评论失败",url('showpiccomment/index',['id'=>input('showpicid')]));
        }
      }
  }
	
	public function delShowpic($id,$pid){
    
		if (Db::name("comments")->where('s_id',$id)->delete()) {
      $this->success('删除成功',url('showpiccomment/index',['id'=>$pid]));
    }else 
    $this->error('删除失败',url('showpiccomment/index',['id'=>$pid]));
	}


    public function getPic(){

        $rs=Db::name('pictures')->select();
        return json($rs);
    }




}